<?php

class UserTest extends BaseTest
{
    public function testInsert()
    {
        $class = new \Orm\User\UserClass();
		$class['username'] = $this->testStr();
		$class['password'] = $this->testStr();
		$class['nickname'] = $this->testStr();
		$class['openid'] = $this->testStr();
		$class['unionid'] = $this->testStr();
		$class['province'] = $this->testStr();
		$class['city'] = $this->testStr();
		$class['country'] = $this->testStr();
		$class['photo'] = $this->testStr();
		$class['sex'] = $this->testNum();


        $class->insert();
        $result_class = new \Orm\User\UserClass();
        $result_class->loadById($class['id']);

		$this->assertEquals($class['username'],$result_class['username']);
		$this->assertEquals($class['password'],$result_class['password']);
		$this->assertEquals($class['nickname'],$result_class['nickname']);
		$this->assertEquals($class['openid'],$result_class['openid']);
		$this->assertEquals($class['unionid'],$result_class['unionid']);
		$this->assertEquals($class['province'],$result_class['province']);
		$this->assertEquals($class['city'],$result_class['city']);
		$this->assertEquals($class['country'],$result_class['country']);
		$this->assertEquals($class['photo'],$result_class['photo']);
		$this->assertEquals($class['sex'],$result_class['sex']);

        return $result_class;
    }

    /**
     * @depends testInsert
     */
    public function testUpdate($class)
    {
		$class['nickname'] = $this->testStr();
		$class['openid'] = $this->testStr();
		$class['province'] = $this->testStr();
		$class['city'] = $this->testStr();
		$class['country'] = $this->testStr();
		$class['photo'] = $this->testStr();
		$class['sex'] = $this->testNum();


        $class->update();
        $result_class = new \Orm\User\UserClass();
        $result_class->loadById($class['id']);
		$this->assertEquals($class['nickname'],$result_class['nickname']);
		$this->assertEquals($class['openid'],$result_class['openid']);
		$this->assertEquals($class['province'],$result_class['province']);
		$this->assertEquals($class['city'],$result_class['city']);
		$this->assertEquals($class['country'],$result_class['country']);
		$this->assertEquals($class['photo'],$result_class['photo']);
		$this->assertEquals($class['sex'],$result_class['sex']);

        return $result_class;
    }

    /**
     * @depends testUpdate
     */

    public function testDelete($class)
    {
        $class->delete($class['id']);

        $result_class = new \Orm\User\UserClass();
        $result_class->loadById($class['id']);
        $this->assertEquals(1, $result_class['is_del']);
        return $result_class;
    }


    /**
     * @depends testInsert
     */
    public static function testClean($class)
    {
        if ($class['id']) {
            $class->realDelete($class['id']);
        }
    }
}